package com.project.server.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.server.common.Result;
import com.project.server.model.Staff;
import com.project.server.service.StaffService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Tag(name = "员工管理")
@RestController
@RequestMapping("/api/staff")
@RequiredArgsConstructor
public class StaffController {

    private final StaffService staffService;

    @Operation(summary = "分页查询员工")
    @GetMapping("/page")
    public Result<Page<Staff>> page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String phone,
            @RequestParam(required = false) Long restaurantId,
            @RequestParam(required = false) Integer status) {
        return Result.success(staffService.page(pageNum, pageSize, name, phone, restaurantId, status));
    }

    @Operation(summary = "新增/修改员工")
    @PostMapping
    public Result<?> save(@RequestBody Staff staff) {
        staffService.saveOrUpdate(staff);
        return Result.success();
    }

    @Operation(summary = "删除员工")
    @DeleteMapping("/{id}")
    public Result<?> remove(@PathVariable Long id) {
        staffService.removeById(id);
        return Result.success();
    }


    @Operation(summary = "更新状态")
    @PutMapping("/status/{id}/{statu}")
    public Result<?> status(@PathVariable Long id,@PathVariable Integer statu) {
        Staff staff = staffService.getById(id);
        staffService.updateStatus(id, statu);
        return Result.success();
    }



    @Operation(summary = "更新员工信息")
    @PostMapping("/updateStaff")
    public Result<?> status(@RequestBody Staff staff) {
        staffService.saveOrUpdate(staff);
        return Result.success();
    }













}
